<template>
    <div class='commonPrint' v-loading="loading2">
        <div class='skins' v-show="skins">正在生成中...</div>
        <div class='btn' >
            <!--button v-print="printObj">打印</button--> 
            
            <!--button onClick="javascript:window.print();">打印</button--> 
            <el-button type="primary" @click="printPreview(0,-1)" v-if="isApp!='Y'&&isPrintOk">打印</el-button>
            <el-button type="primary" @click="printPreview(0,-1,'N')" v-if="isApp!='Y'&&isPrintOk">打印(不控制纸张)</el-button>
            <el-button type="primary" @click="savePrintSignature()" v-if="showQm||showQm2||showQm3" >保存</el-button>
            <el-button type="primary" @click="resetSigns()" v-if="showQm4" >重签</el-button>
            <el-button type="primary" @click="jfsign('甲方')" v-if="showQm">甲方签字</el-button>
            <el-button type="primary" @click="jfsign('乙方')" v-if="showQm2">乙方签字</el-button>
            <el-button type="primary" @click="resetSign" v-if="isSignReset=='Y'">重置签名</el-button>
            <el-button type="primary" @click="transs()" >翻转</el-button>
            <el-button type="primary" @click="printPreview(1,-1)">预览</el-button>
            <el-button type="primary" @click="isSet='Y'" style="float:right">设置</el-button>
            <el-button type="primary" @click="setPrintClose('Y')" style="float:right" v-if="isPrintClose!='Y'">设置打印后关闭</el-button>
            <el-button type="primary" @click="setPrintClose('N')" style="float:right" v-if="isPrintClose=='Y'">设置打印后不关闭</el-button>
        </div>
        <div class='head' v-if="showForm" v-show="isApp!='Y'&&isSet=='Y'">
            <div class='head_left'>
                <el-form :inline="true"  :model="printData"  class="demo-form-inline">
                    <el-form-item label="纸张宽" label-width="90px">
                        <el-input v-model="printData.c_ex9" placeholder="纸张宽" size="small" style="width:100px"></el-input>mm
                    </el-form-item>
                    <el-form-item label="纸张长" label-width="90px">
                        <el-input v-model="printData.c_ex10" placeholder="纸张长" size="small" style="width:100px"></el-input>mm
                    </el-form-item>
                    <el-form-item label="打印方向" label-width="90px">
                        <el-select v-model="printData.c_ex5" placeholder="请选择" style="width:100px">
                            <el-option
                                label="横"
                                value="2">
                            </el-option>
                            <el-option
                                label="竖"
                                value="1">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="报表分页" label-width="90px">
                        <el-input v-model="printData.c_ex16" placeholder="报表分页" size="small" style="width:100px"></el-input>条/页
                    </el-form-item>
                    <el-form-item label="左边距" label-width="90px">
                        <el-input v-model="printData.c_ex7" placeholder="左边距" size="small" style="width:100px"></el-input>mm
                    </el-form-item>
                    <el-form-item label="上边距" label-width="90px">
                        <el-input v-model="printData.c_ex8" placeholder="上边距" size="small" style="width:100px"></el-input>mm
                    </el-form-item>
                    <el-form-item label="打印份数" label-width="90px">
                        <el-input v-model="printData.c_ex17" placeholder="上边距" size="small" style="width:100px"></el-input>份
                    </el-form-item>
                     <el-form-item label="打印模式" label-width="90px">
                        <el-select v-model="printData.c_ex22" placeholder="请选择" style="width:100px">
                            <el-option
                                label="不控制"
                                value="0">
                            </el-option>
                            <el-option
                                label="单面打印"
                                value="1">
                            </el-option>
                             <el-option
                                label="双面打印"
                                value="2">
                            </el-option>
                            <el-option
                                label="单面打印(纸张不控制)"
                                value="4">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="缩放" label-width="90px">
                        <el-select v-model="printData.c_ex18" placeholder="请选择" style="width:100px">
                            <el-option
                                label="自适应宽度"
                                value="Auto-Width">
                            </el-option>
                            <el-option
                                label="自适应高度"
                                value="Auto-Height">
                            </el-option>
                             <el-option
                                label="拉伸至纸张宽度"
                                value="Full-Width">
                            </el-option>
                             <el-option
                                label="拉伸至纸张高度"
                                value="Full-Height">
                            </el-option>
                             <el-option
                                label="铺满纸张"
                                value="Full-Page">
                            </el-option>
                            <el-option
                                label="100%"
                                value="width:100%;height:100%">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    
                   
                </el-form>
            </div>
            <div class='head_right'>
                 <el-button type="primary" @click="savePrint" style='width:100px;margin-left:20px'>保存</el-button>
                 <el-button type="primary" @click="isSet='N'" style='width:100px;margin-left:20px;margin-top:20px'>关闭</el-button>
            </div>
            
        </div>
       
        
        <div  id="printContent" :class="{'printContent':true, 'commonPrint_trans':trans}" ref="print" style="text-align:center">
            <div style="width:100%;text-align:center">
                <img :src="urlPath" v-if="urlPath!=''" style='max-width:100%;' ref="printImg"/>
            </div>
            
        </div>
        <el-dialog title="选择网络打印机"
          class="pringsleect"
           append-to-body :visible.sync="outerVisible">
            
                选择打印机:
                <div style='width:100%;text-align:center'>
                <el-select style="width:80%" v-model="print1" placeholder="请选择" @change="changePrint">
                    <el-option
                    v-for="item in netWorkPrintMain"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                </div>
                <div v-if="showprint"  style='width:100%;text-align:center'>
                <el-select v-model="netWorkPrintValue" placeholder="请选择" @change="changePrint2">
                    <el-option
                    v-for="item in netWorkPrint"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                
                </el-select>
                </div>
                <div  v-if="showprint2"  style='width:100%;text-align:center'>
                <el-select v-model="netWorkPrintValue2" placeholder="请选择">
                    <el-option
                    v-for="item in netWorkPrint2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                </div>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="outerVisible = false">取 消</el-button>
                    <el-button type="primary" @click="prints()">确定</el-button>
                </div>
            
        </el-dialog>


        <el-dialog title="签字" class="signatures"
          style="overflow:hidden"
           append-to-body :visible.sync="qzShow">
           
                签字:
                <div style='width:100%;text-align:center'>
                    <signature ref="signature"></signature>
                </div>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="delsignature">清空</el-button>
                    <el-button @click="qzShow = false">取 消</el-button>
                    <el-button type="primary" @click="qzok()">确定</el-button>
               
           </div>  
          
        </el-dialog>
        <el-dialog title="图片查看" class="signaturess"
          
           append-to-body :visible.sync="qzShow2">
           <div style='width:100%;height:60VH;overflow-x:hidden' >
                <img :src="qzImg" style='width:100%'/>
           </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="qzShow2 = false">关闭</el-button>
            </div>
        </el-dialog>
        
    </div>

</template>
<script>
import { getLodop } from '../../../utils/LodopFuncs'

import QRCode from 'qrcodejs2'  // 引入qrcode
import JsBarcode  from 'jsbarcode'  // 引入qrcode
import html2canvas from "html2canvas"
import axios from 'axios';
export default {
    name:"commonPrint",
    props:["printDatas"],
    components: { 
         signature: resolve => {require(['../../../components/common/signature'], resolve)}
    },
    data(){
        return{
            trans:false,
            printObj:{
                id:'printContent',
                popTitle:'',
                extraCss:'',
                extraHead:'<meta http-equiv="Content-Laguage" content="zh-cn"/>' 
            },
            sKey:'',
            isSet:"N",
            loading2:false,
            printName:'',
            printTitle:"",
            sType:'',
            printData:{ },
            content:'',
            showForm:false,
            sCurItem:'',
            printId:"",
            sCurItems:'',
            urlPath:"",
            urlMain:"http://8.136.193.200",
            isPrint:'N',
            token:'',
            appid:"",
            searchData:{},
            isEwm:false,
            signType:'',
            apiUrl:'http://localhost:8089/PPSignSDK/',
            LastSignatureBase64Data:"",
            isPolling:false,
            canvas:null,
            context:null,
            netWorkPrint:[],
            netWorkPrint2:[],
            netWorkPrintMain:[],
            netWorkPrintValue:"",
            netWorkPrintValue2:"",
            outerVisible:false,
            qzShow:false,
            qzShow2:false,
            qzType:"",
            print1:"",
            showprint:false,
            showprint2:false,
            isSearch:"N",
            signatureImg:"",
            isApp:localStorage.getItem("isApp"),
            fileType:"",
            fileName:"",
            fileModel:"",
            skins:false,
            qzImg:"",
            showQm:false,
            showQm2:false,
            showQm3:false,
            showQm4:false,
            isPrintOk:true,
            appid2:"",
            posturl:"",
            params:"",
            isSaveSignature:false,
            savePrintUrl:"",
            isSignStop:"N",
            isSings:"N",
            isSignReset:"N",
            signTypes:"",
            isNotSavePrint:"N",
            isNotSaveImg:"N", //暂时不用
            isPrintClose:"Y"
        }
    },
    created(){
       
       /* const s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = '';
        document.body.appendChild(s);*/

        if(this.$route.query.sKey){
            this.sKey=this.$route.query.sKey;
        }else if(this.printDatas){
            this.sKey=this.printDatas.sKey;
        }
        try{
            if(this.printDatas.isSearch){
                this.isSearch=this.printDatas.isSearch;
            }
        }catch(e){}
        if(this.$route.query.printName){
            this.printName=this.$route.query.printName;
            this.searchData["printName"]=this.$route.query.printName;
        }else if(this.printDatas){
            this.printName=this.printDatas.printName;
            this.searchData["printName"]=this.printDatas.printName;
        }
        if(this.$route.query.printTitle){
            this.printTitle=this.$route.query.printTitle;
            this.searchData["printTitle"]=this.$route.query.printTitle;
        }else if(this.printDatas){
            this.printTitle=this.printDatas.printTitle;
            this.searchData["printTitle"]=this.printDatas.printTitle;
        }
        if(this.$route.query.sType){
            this.sType=this.$route.query.sType;
        }else if(this.printDatas){
            this.sType=this.printDatas.sType;
        }
         if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }else if(this.printDatas){
            this.appid=this.printDatas.appid;
        }
        try{
            if(this.printDatas.params){
                this.params=this.printDatas.params;
            }
        }catch(e){}
        
        
        if(this.$route.query.sId){
            this.sId=this.$route.query.sId;
        }else if(this.printDatas){
            this.sId=this.printDatas.sId;
        }
        if(this.$route.query.sCurItem){
            this.sCurItem=this.$route.query.sCurItem;
            this.searchData["sCurItem"]=this.$route.query.sCurItem;
        }else if(this.printDatas){
            this.sCurItem=this.printDatas.sCurItem;
            this.searchData["sCurItem"]=this.printDatas.sCurItem;
        }
        if(this.$route.query.sCurItems){
            this.sCurItems=this.$route.query.sCurItems;
            this.searchData["sCurItems"]=this.$route.query.sCurItems;
        }else if(this.printDatas&&this.printDatas.sCurItems){
            this.sCurItems=this.printDatas.sCurItems;
            this.searchData["sCurItems"]=this.printDatas.sCurItems;
        }
        if(this.$route.query.urlPath){
            
            this.urlPath=this.$route.query.urlPath;
        }else if(this.printDatas){
           
            if(this.printDatas.urlPath&&this.printDatas.urlPath.indexOf("http://")==-1&&this.printDatas.urlPath.indexOf("https://")==-1)
                this.urlPath=this.urlMain+this.printDatas.urlPath;
            else if(this.printDatas.urlPath){
                    this.urlPath=this.printDatas.urlPath;
                }
           // this.urlPath=this.urlPath.replace("192.168.40.11:18800","218.92.42.166:15555")
        }
        if(this.$route.query.printId){
            this.printId=this.$route.query.printId;
        }else if(this.printDatas){
            if(this.printDatas.printId)
                this.printId=this.printDatas.printId;
        }

        if(this.$route.query.token){
            this.token=this.$route.query.token;
        }else if(this.printDatas){
            this.token=this.printDatas.token;
        }
        if(this.$route.query.isPrint=='Y'){
            this.isPrint='Y'
        }else if(this.printDatas){
            this.isPrint=this.printDatas.isPrint;
        }
        if(this.$route.query.page){
            this.searchData["page"]=this.$route.query.page;
        }else if(this.printDatas){
            this.searchData["page"]=this.printDatas.page;
        }
        if(this.$route.query.limit){
            this.searchData["limit"]=this.$route.query.limit;
        }else if(this.printDatas){
            this.searchData["limit"]=this.printDatas.limit;
        }

        if(this.$route.query.sKey){
            this.searchData["sKey"]=this.$route.query.sKey;
        }else if(this.printDatas){
            this.searchData["sKey"]=this.printDatas.sKey;
        }

        if(this.$route.query.sKey2){
            this.searchData["sKey2"]=this.$route.query.sKey2;
        }else if(this.printDatas){
            this.searchData["sKey2"]=this.printDatas.sKey2;
        }

        if(this.$route.query.listname){
            this.searchData["listname"]=this.$route.query.listname;
        }else if(this.printDatas){
            this.searchData["listname"]=this.printDatas.listname;
        }

        if(this.$route.query.dataEx){
            this.searchData["dataEx"]=unescape(this.$route.query.dataEx);
        }else if(this.printDatas){
            this.searchData["dataEx"]=unescape(this.printDatas.dataEx);
        }

        if(this.$route.query.data){
            this.searchData["data"]=unescape(this.$route.query.data);
        }else if(this.printDatas){
            this.searchData["data"]=unescape(this.printDatas.data);
        }
        if(this.$route.query.company){
            this.searchData["company"]=this.$route.query.company;
        }else if(this.printDatas){
            this.searchData["company"]=this.printDatas.company;
        }
       
        if(this.printName&&!this.urlPath){
             this.loadData();
        }
        if( localStorage.getItem(localStorage.getItem("sCode")+"isPrintClose")){
            this.isPrintClose= localStorage.getItem(localStorage.getItem("sCode")+"isPrintClose")
        }   
       
    },
    beforeDestroy(){
        this.isPolling=false;
        try{
            this.uninitDevice();
        }catch(e){}
        try{
            this.uninitDeviceESP560();
        }catch(e){}
        
    },
    mounted(){
       
    },
    activated(){
        
        this.trans=false;
    },
     watch:{
        printDatas:{
            handler: function (newVal) {
                this.trans=false;
                // console.log("data===================================================")
                this.sKey=this.printDatas.sKey;
                this.printName=this.printDatas.printName;
                this.searchData["printName"]=this.printDatas.printName;
                this.searchData["printTitle"]=this.printDatas.printTitle;
                this.sType=this.printDatas.sType;
                this.appid=this.printDatas.appid;
                
                this.sId=this.printDatas.sId;
                this.sCurItem=this.printDatas.sCurItem;
                this.searchData["sCurItem"]=this.printDatas.sCurItem;
                if(this.printDatas.sCurItems){
                    this.sCurItems=this.printDatas.sCurItems;
                    this.searchData["sCurItems"]=this.printDatas.sCurItems;
                }
                if(this.printDatas.urlPath&&this.printDatas.urlPath.indexOf("http://")==-1&&this.printDatas.urlPath.indexOf("https://")==-1){
                    this.urlPath=this.urlMain+this.printDatas.urlPath;
                }else if(this.printDatas.urlPath){
                    this.urlPath=this.printDatas.urlPath;
                }
                if(this.printDatas.printId){
                    this.printId=this.printDatas.printId;
                }
                
                
                this.token=this.printDatas.token;
                this.isPrint=this.printDatas.isPrint;
                this.searchData["page"]=this.printDatas.page;
                this.searchData["limit"]=this.printDatas.limit;

                this.searchData["sKey"]=this.printDatas.sKey;

                this.searchData["sKey2"]=this.printDatas.sKey2;

                this.searchData["listname"]=this.printDatas.listname;

                this.searchData["dataEx"]=unescape(this.printDatas.dataEx);

                this.searchData["data"]=unescape(this.printDatas.data);
                this.searchData["company"]=this.printDatas.company;
                console.log("this.printData=========================")
                console.log(this.printDatas);
                if(!this.urlPath)
                    this.loadData()
            },      
            deep: true    //深度监听
        }
    },
    methods:{
        jfsign(type){
            try{
                this.$refs.signature.deleteImg();
            }catch(e){}
            
            this.qzType=type;
            this.qzShow=true;
        },
        delsignature(){
             try{
                this.$refs.signature.deleteImg();
            }catch(e){}
        },
        setPrintClose(isClose){
            this.isPrintClose=isClose;
            localStorage.setItem(localStorage.getItem("sCode")+"isPrintClose",isClose)
        },
        qzok(){
            let signature=this.$refs.signature.getSignature();
            let that=this;
            console.log(signature,"signature=============")
            if(this.trans){
                this.rotateBase64Img(signature,180,function(data){
                
                    console.log(data,"signature2==========")
                    that.signatureImg=data;
                    that.qzShow=false;
                    if(that.qzType=="甲方"){
                        let elms=document.getElementsByClassName('signaturejf');
                        for(let i=0;i<elms.length;i++){
                            elms[i].src=data;
                            that.fileType=elms[i].getAttribute("fileType");
                            that.fileName=elms[i].getAttribute("fileName");
                            that.fileModel=elms[i].getAttribute("fileModel");
                        }
                    }else{
                        let elms=document.getElementsByClassName('signatureyf');
                        for(let i=0;i<elms.length;i++){
                            elms[i].src=data;
                            that.fileType=elms[i].getAttribute("fileType");
                            that.fileName=elms[i].getAttribute("fileName");
                            that.fileModel=elms[i].getAttribute("fileModel");
                            //alert(this.fileType+"="+this.fileName)
                        }
                    }
                    that.isSaveSignature=true;
                })
            }else{
                this.signatureImg=signature;
                this.qzShow=false;
                if(this.qzType=="甲方"){
                    let elms=document.getElementsByClassName('signaturejf');
                    for(let i=0;i<elms.length;i++){
                        elms[i].src=signature;
                        this.fileType=elms[i].getAttribute("fileType");
                        this.fileName=elms[i].getAttribute("fileName");
                        this.fileModel=elms[i].getAttribute("fileModel");
                    }
                }else{
                    let elms=document.getElementsByClassName('signatureyf');
                    for(let i=0;i<elms.length;i++){
                        elms[i].src=signature;
                        this.fileType=elms[i].getAttribute("fileType");
                        this.fileName=elms[i].getAttribute("fileName");
                        this.fileModel=elms[i].getAttribute("fileModel");
                        //alert(this.fileType+"="+this.fileName)
                    }
                }
                this.isSaveSignature=true;
            }
            
            
        },
        savePrint(){
            this.$post("business","/api/print/savePrint",{
                printName:escape(this.printName),
                data:JSON.stringify(this.printData)
            }).then(data=>{
                 this.$message({
                    message: '保存成功',
                    type: 'success'
                    });
            })
        },
        
        loadData(){
           /* const loading = this.$loading({
                    lock: true,
                    text: '打印加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });*/
            this.isPrintOk=false;
            this.$post("business","/api/print/printCenter",{sKey:this.sKey,printName:this.printName,sType:this.sType,osmsg:localStorage.getItem("osmsg"),"sCurItem":this.sCurItem}).then(data=>{
                this.printData=data;
                let url=data.c_ex2;
                let isJsPrint=data.c_ex23
                let zoom=data.c_ex24;
                this.signType="";
                if(data.c_ex2){
                    let urls=url.split("#");
                    url=urls[0];
                    let c_ex12=data.c_ex12;
                    let printNum=Number(data.printNum);
                   
                    let c_ex21=data.c_ex21;//默认打印机名称
                    if(c_ex21){
                        printNum=c_ex21;
                    }

                    if(c_ex12!="Y")
                        this.showForm=true;
                    url=url.indexOf("?")==-1? url+"?cms="+this.cm2px(this.printData.c_ex9)+"&token="+this.token:url+"&cms="+this.cm2px(this.printData.c_ex9)+"&token="+this.token
                    url=url+"&sCurItem="+this.sCurItem+"&sCurItems="+this.sCurItems+"&printId="+this.printId;
                // alert(this.appid+"="+url);
                    let appid=this.appid;
                    
                    appid=urls.length>1 ? urls[1]:appid;
                    //alert(unescape(this.searchData.listname))
                    this.loading2=true;
                    this.appid2=appid;
                    this.posturl=url;
                    for(let key in this.params){
                        this.searchData[key]=this.params[key]
                    }
                    this.$post(appid,url,this.searchData).then(data=>{
                        if(this.isSearch=="Y"){
                            this.$emit("goSearch","")
                        }
                        this.loading2=false;
                        let isOks=true;
                        try{
                            if(data[0].status=="-ERR"){
                                this.$alert(data[0].msg, {
                                            confirmButtonText: '确定',
                                        callback: action => {
                                        
                                        }
                                    });
                                    isOks=false;
                            }
                        }catch(e){}
                        if(!isOks){
                            return;
                        }
                        try{
                            if(data[0].msg){
                                this.$alert(data[0].msg, {
                                        confirmButtonText: '确定',
                                        callback: action => {
                                        
                                        }
                                });
                            }
                        }catch(e){}
                        
                        if(c_ex12!="Y"){//不是套打
                        let sef=this;
                           
                            this.content=unescape(data[0].content);
                            this.savePrintUrl=data[0].savePrintUrl;
                            document.getElementsByClassName('printContent')[document.getElementsByClassName('printContent').length-1].innerHTML =unescape(data[0].content);
                            //document.getElementsByClassName('printContent')[0].innerHTML =unescape(data[0].content);
                            

                           /* const document = window.document;
                            const iframe = window.frames[0];
                            iframe.document.head.innerHTML = document.head.innerHTML;
                            iframe.document.body.innerHTML = unescape(data[0].content);
                    
                            //   打印
                            setTimeout(() => {
                                iframe.window.print();
                            }, 200);*/
                            

                            
                            
                            console.log("c_ex12========================================================111")
                            window.setTimeout(function(){
                                //手写板
                                try{
                                    sef.canvas = document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1];
                                    
                                    sef.fileType=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("fileType");;
                                    sef.fileName=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("fileName");
                                    sef.fileModel=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("fileModel");
                                    let singType=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("signType");
                                    let src=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("src");
                                    

                                    this.isNotSavePrint=document.getElementsByClassName('ppCanvas')[document.getElementsByClassName('ppCanvas').length-1].getAttribute("isNotSavePrint");
                                    //isNotSavePrint

                                    console.log("signTYPE==================="+singType+"=="+src)
                                    if(sef.canvas){
                                        this.signtypes=singType;
                                       /* if (sef.canvas.getContext) {
                                            sef.context = sef.canvas.getContext('2d');
                                        }*/
                                        sef.isSings="Y";
                                        if(!src){
                                            if(singType=="ESP560"){
                                                sef.isSignReset="Y"
                                                sef.initDeviceEsp560();
                                            }else
                                                sef.initDevice();
                                            sef.showQm3=true;
                                        }else{
                                            
                                            sef.showQm4=true;
                                        }
                                        
                                       
                                    }
                                    
                                }catch(e){console.log(e.message,"e.message==================")}
                               // alert(document.getElementsByClassName('signatureyf').length);
                                try{
                                    if(document.getElementsByClassName('signaturejf').length>0)
                                        sef.showQm=true;
                                    if(document.getElementsByClassName('signatureyf').length>0)
                                        sef.showQm2=true;
                                }catch(e){}


                               

                                let qrcode=document.getElementsByClassName("qrcode");
                                try{
                                    let sign=document.getElementsByClassName("sign");
                                    if(sign&&sign.length>0){
                                        sef.signType=sign[0].getAttribute("type");
                                    }
                                }catch(e){}
                                
                                //平板签字
                                try{
                                    
                                }catch(e){}
                                //二维码
                                
                                for(let i=0;i<qrcode.length;i++){
                                    let id=qrcode[i].getAttribute("id");
                                    console.log("qrcode=id====="+id);
                                    let flagWidth=qrcode[i].getAttribute("flagWidth");
                                    let flagValue=qrcode[i].getAttribute("flagValue");
                                    document.getElementById(id).innerHTML="";
                                    sef.qrcode(id,flagWidth,flagValue);
                                    sef.isEwm=true;
                                }


                                //条形码
                                let jsbar=document.getElementsByClassName("jsbar");
                            
                                for(let i=0;i<jsbar.length;i++){
                                    let id=jsbar[i].getAttribute("flagid");
                                   
                                    let flagWidth=jsbar[i].getAttribute("flagWidth");
                                    let flagHeight=jsbar[i].getAttribute("flagHeight");
                                    let flagValue=jsbar[i].getAttribute("flagValue");
                                    JsBarcode("#"+id, flagValue), {

                                　　 　　   width: 3,
                                　　 　　   height: 40
                                　　　　};
                                }

                                if(qrcode.length>0){
                                    window.setTimeout(()=>{
                                        sef.isPrintOk=true;
                                    },200)
                                }else{
                                    sef.isPrintOk=true;
                                }
                                if(sef.isPrint=='Y'){
                                
                                    if(isJsPrint=="Y"){
                                        var newWin = window.open(""); //新打开一个空窗口
                                    
                                        newWin.document.write(unescape(data[0].content)); //将需要打印的内容添加进新的窗口
                                        //const styleSheet = `<meta http-equiv="Content-Laguage" content="zh-cn"/><style>@page {size: auto;  margin: 0mm;}body{width:100%;word-wrap:break-word;zoom:80%;}</style>`;
                                        let styleSheet = '<meta http-equiv="Content-Laguage" content="zh-cn"/><title>'+sef.printName+'</title><style>@page {size: auto;  margin: 0mm;}body{width:100%;word-wrap:break-word;'
                                    
                                        if(zoom){
                                            styleSheet += 'zoom:'+zoom;
                                        }
                                        styleSheet+='}</style>';
                                        //alert(styleSheet);
                                        newWin.document.head.innerHTML = styleSheet; //给打印的内容加上样式
                                        newWin.document.close(); //在IE浏览器中使用必须添加这一句
                                        newWin.focus(); //在IE浏览器中使用必须添加这一句
                                        setTimeout(function() {
                                            newWin.print(); //打印
                                            newWin.close(); //关闭窗口
                                        }, 100);
                                    }else{
                                        /* if(printNum!=-1){
                                            LODOP.SET_PRINTER_INDEX(printNum)
                                        }*/
                                        if(qrcode.length>0){
                                            window.setTimeout(function(){
                                                sef.printPreview(0,printNum);
                                            //  loading.close();
                                            },1000)
                                        }else
                                            sef.printPreview(0,printNum);
                                        //  loading.close();
                                        
                                    }
                                    
                                

                                }else{
                                 //   loading.close();
                                }


                                    
                            },1000)
                        }else{
                            LODOP = getLodop();
                         //   alert(unescape(data[0].content))
                            eval(unescape(data[0].content));
                            
 
                            LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW",1);
                            LODOP.SET_PREVIEW_WINDOW(1,1,0,0,0,""); //隐藏工具条，设置适高显示
                        // LODOP.SET_SHOW_MODE("PREVIEW_IN_BROWSE",true); //预览界面内嵌到页面内
                     //   loading.close();
                            if(this.isPrint=='Y'){
                            //     loading.close();
                                
                                if(printNum!=-1){
                                    if(LODOP.SET_PRINTER_INDEX(printNum)){
                                        LODOP.PRINT();
                                    }
                                    //LODOP.SET_PRINTER_INDEXA(printNum)
                                }else{
                                    var count = LODOP.GET_PRINTER_COUNT();
                                    this.netWorkPrintMain=[];
                                    for (var i = 0; i < count; i++) {
                                        //根据设备序号获取设备名
                                        var msg = LODOP.GET_PRINTER_NAME(i);
                                        let option={};
                                        option.label=msg;
                                        option.value=i;
                                        this.netWorkPrintMain.push(option);
                                    
                                    }
                                    
                                    this.outerVisible=true;
                                    this.$nextTick(function () {
                                        // Code that will run only after the
                                        // entire view has been rendered
                                        let that=this;
                                        if( localStorage.getItem(localStorage.getItem("sCode")+that.printName+"print1")){
                                            that.print1=Number(localStorage.getItem(localStorage.getItem("sCode")+that.printName+"print1"))
                                            this.changePrint();
                                        }else{
                                            that.print1=""; 
                                            this.netWorkPrintValue2="";
                                            this.netWorkPrintValue="";
                                        }
                                    
                                    
                                    
                                    })
                                }
                                
                               
                               // LODOP.SELECT_PRINTER();
                                //LODOP.PRINTA();
                            }else{
                           //     loading.close();
                                LODOP.PREVIEW();
                            }
                            
                                
                        }
                        
                        
                    })
                }else{

                 //   loading.close();
                     this.$alert('该打印未配置，请联系维护人员', '打印出错', {
                        confirmButtonText: '确定',
                        callback: action => {
                        
                        }
                    });
                }
                
            })
        },
        print(){
            this.$print(this.$refs.print)
        },
        //保存签字图片
        savePrintSignature(){
             
           
            /*let url=this.posturl;
            sef.$post(this.appid2,this.posturl,{type:"image",printHtml:this.printHtml,signature:sef.signatureImg,sCurItem:sef.sCurItem}).then(data=>{
                        
                console.log("uploadImg==========================");
                console.log(unescape(data[0].content));
                sef.loading2=false;
                sef.skins=false;
               // sef.qzImg=data.url;
               // sef.qzShow2=true;
                
            });	*/
            //return;
            //alert(sef.$refs.print.scrollHeight+"="+sef.$refs.print.offsetHeight);
            if(!this.signatureImg){
                 this.$message.error('请先签名');
                // return;
            }

            this.loading2=true;
            this.skins=true;
           //document.querySelector('#wt')
            let sef=this;
            window.setTimeout(function(){
               // alert(sef.isNotSaveImg)
                if( sef.isNotSaveImg=="Y"){
                    sef.$post("business","/api/saveSignImage",{url:"",type:sef.printName,signature:sef.signatureImg,fileType:sef.fileType,fileName:sef.fileName,fileModel:sef.fileModel,fileId:"",sCurItem:sef.sCurItem}).then(data2=>{
                            sef.loading2=false;
                            sef.skins=false;
                            sef.qzImg=data[0].url;
                            sef.qzShow2=true;
                            sef.isSaveSignature=false;//保存过了，不用在重新保存
                            sessionStorage.setItem("reloadImg","Y")
                        // alert(sef.qzImg+"=="+data2.url)
                            if(sef.savePrintUrl){
                                sef.$post(sef.appid2,sef.savePrintUrl,{}).then(json=>{
                                    
                                })
                            }
                            
                        })
                }else{
                    html2canvas(document.querySelector('#printContentDetail'),{
                        scale: 2, //设置放大的倍数
                        useCORS: true,
                        allowTaint: false,
                        dpi: 600,
                        height: sef.$refs.print.scrollHeight,
                        windowHeight: sef.$refs.print.scrollHeight
                    }).then(canvas => {
                    
                        let dataURL = canvas.toDataURL("image/png");
                    // console.log(dataURL)
                    
                        sef.$post("business","/api/file/fileUploadBase64",{data:dataURL,token:this.token}).then(data=>{
                            
                            let url=data[0].url;
                            let f_id=data[0].f_id;
                            if(url){
                                if(!sef.fileModel){
                                    sef.fileModel="";
                                }
                                sef.$post("business","/api/saveSignImage",{url:url,type:sef.printName,signature:sef.signatureImg,fileType:sef.fileType,fileName:sef.fileName,fileModel:sef.fileModel,fileId:f_id,sCurItem:sef.sCurItem}).then(data2=>{
                                    sef.loading2=false;
                                    sef.skins=false;
                                    sef.qzImg=data[0].url;
                                    sef.qzShow2=true;
                                    sef.isSaveSignature=false;//保存过了，不用在重新保存
                                    sessionStorage.setItem("reloadImg","Y")
                                // alert(sef.qzImg+"=="+data2.url)
                                    if(sef.savePrintUrl){
                                        sef.$post(sef.appid2,sef.savePrintUrl,{}).then(json=>{
                                            
                                        })
                                    }
                                    
                                })
                            }
                        });	
                        
                        
                        // this.clearInk();
                    });
                }
                
            },500)
            
        },
        printPreview(s,printNum,isControl) {
            console.log("printPreview===========================")
            if(this.isSings=="Y"){
               // this.uninitDevice2();
            }
            let sef=this;
           /* console.log(document.getElementsByClassName('ppCanvas'),"ppCanvas===")
            console.log(document.getElementsByClassName('ppCanvas').length,"ppCanvas===")
            console.log(document.getElementsByClassName('signaturejf'),"signaturejf===")
            console.log(document.getElementsByClassName('signatureyf'),"signatureyf===")
            console.log(document.getElementsByClassName('signaturejf').length,"signaturejf===")
            console.log(document.getElementsByClassName('signatureyf').length,"signatureyf===")*/
            if((document.getElementsByClassName('ppCanvas')&&document.getElementsByClassName('ppCanvas').length>0)||(document.getElementsByClassName('signaturejf')&&document.getElementsByClassName('signaturejf').length>0)||(document.getElementsByClassName('signatureyf')&&document.getElementsByClassName('signatureyf').length>0)){
                console.log("111111111111111111")
                let isSaveImage=true;
                if(!this.isSaveSignature){
                    isSaveImage=false;
                }
                if(this.isNotSavePrint=="Y"){
                    isSaveImage=false;
                }
                //isSaveImage=true;
                if(isSaveImage){
                     this.isPolling=false;
                    this.loading2=true;

                    let obj=null;
                    let height=0;
                    if(document.getElementById("printContentDetail")&&document.getElementById("printContentDetail").length>0){
                        obj=document.querySelector('#printContentDetail');
                        height=this.$refs.print.scrollHeight;
                    }else{
                        obj=this.$refs.print
                        height=this.$refs.print.scrollHeight+this.$refs.print.offsetHeight
                    }
                    //console.log("22222222222222222222222222222")
                    if( sef.isNotSaveImg=="Y"){
                        sef.$post("business","/api/saveSignImage",{url:"",type:sef.printName,signature:sef.signatureImg,fileType:sef.fileType,fileName:sef.fileName,fileModel:fileModel,fileId:"",sCurItem:sef.sCurItem}).then(data=>{
                            //this.$post("business","/api/saveSignImage",{url:url,type:this.printName}).then(data=>{
                                sessionStorage.setItem("reloadImg","Y")
                            })
                    }else{
                        html2canvas(obj,{
                            scale: 2, //设置放大的倍数
                            useCORS: true,
                            allowTaint: false,
                            dpi: 300,
                            height: height,
                            windowHeight: height
                        }).then(canvas => {
                            let dataURL = canvas.toDataURL("image/png");
                            this.$post("business","/api/file/fileUploadBase64",{data:dataURL.replace("data:image/png;base64,",""),token:this.token}).then(data=>{
                            
                                let url=data[0].url;
                                let f_id=data[0].f_id;
                                if(url){
                                    let fileModel="";
                                    if(sef.fileModel){
                                        fileModel=sef.fileModel;
                                    }
                                    sef.$post("business","/api/saveSignImage",{url:url,type:sef.printName,signature:sef.signatureImg,fileType:sef.fileType,fileName:sef.fileName,fileModel:fileModel,fileId:f_id,sCurItem:sef.sCurItem}).then(data=>{
                                    //this.$post("business","/api/saveSignImage",{url:url,type:this.printName}).then(data=>{
                                        sessionStorage.setItem("reloadImg","Y")
                                    })
                                }
                            });	
                            this.loading2=false;
                            
                            
                        // this.clearInk();
                        });
                    }
                    
                }/*else if(this.isNotSavePrint=="Y"){
                    let fileModel="";
                    if(sef.fileModel){
                        fileModel=sef.fileModel;
                    }
                    sef.$post("business","/api/saveSignImage",{url:"",type:sef.printName,signature:sef.signatureImg,fileType:sef.fileType,fileName:sef.fileName,fileModel:fileModel,fileId:"",sCurItem:sef.sCurItem}).then(data=>{
                    //this.$post("business","/api/saveSignImage",{url:url,type:this.printName}).then(data=>{
                        sessionStorage.setItem("reloadImg","Y")
                        this.loading2=false;
                    })
                }    */  
                
            }
             
            this.printPreview2(s,printNum,isControl)
        },
        closes(){
            this.$emit("closes","")
        },
        printPreview2(s,printNum,isControl){
           /* LODOP=getLodop();  
            LODOP.PRINT_INITA(10,10,754,453,"打印控件功能演示_Lodop功能_多页文档");
            LODOP.ADD_PRINT_TEXT(21,300,151,30,"自动居中的标题\n");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",15);
            LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
            LODOP.SET_PRINT_STYLEA(0,"Horient",2);
            LODOP.ADD_PRINT_TEXT(63,38,677,330,document.getElementById("doc1").value);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",15);
            LODOP.SET_PRINT_STYLEA(0,"ItemType",4);
            LODOP.SET_PRINT_STYLEA(0,"Horient",3);
            LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
            LODOP.ADD_PRINT_LINE(53,23,52,725,0,1);
            LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
            LODOP.SET_PRINT_STYLEA(0,"Horient",3);
            LODOP.ADD_PRINT_LINE(414,23,413,725,0,1);
            LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
            LODOP.SET_PRINT_STYLEA(0,"Horient",3);
            LODOP.SET_PRINT_STYLEA(0,"Vorient",1);
            LODOP.ADD_PRINT_TEXT(421,37,144,22,"左下脚的文本小标题");
            LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
            LODOP.SET_PRINT_STYLEA(0,"Vorient",1);
            LODOP.ADD_PRINT_TEXT(421,542,165,22,"右下脚的页号：第#页/共&页");
            LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
            LODOP.SET_PRINT_STYLEA(0,"Horient",1);
            LODOP.SET_PRINT_STYLEA(0,"Vorient",1);
            LODOP.SET_PRINT_MODE("PRINT_DUPLEX",2);
            LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE",1);
           */
          
            if(this.urlPath){
                if(this.printDatas.isLodop=="Y"){
                  
                }else{
                    var newWin = window.open(""); //新打开一个空窗口
                                    
                    newWin.document.write("<img  src='"+this.urlPath+"' style='max-width:90%;margin-left:5%'  />"); //将需要打印的内容添加进新的窗口
                    //const styleSheet = `<meta http-equiv="Content-Laguage" content="zh-cn"/><style>@page {size: auto;  margin: 0mm;}body{width:100%;word-wrap:break-word;zoom:80%;}</style>`;
                    let styleSheet = '<meta http-equiv="Content-Laguage" content="zh-cn"/><title></title><style>@page {size: auto;  margin: 0mm;}body{width:100%;word-wrap:break-word;'
                
                    /* if(zoom){
                        styleSheet += 'zoom:'+zoom;
                    }*/
                    styleSheet+='}</style>';
                    //alert(styleSheet);
                    newWin.document.head.innerHTML = styleSheet; //给打印的内容加上样式
                    newWin.document.close(); //在IE浏览器中使用必须添加这一句
                    newWin.focus(); //在IE浏览器中使用必须添加这一句
                    setTimeout(function() {
                        newWin.print(); //打印
                        newWin.close(); //关闭窗口
                    }, 100);
                    return;
                }
                
               
            }
            this.CreateOneFormPage(isControl)
           // LODOP.PREVIEW();
            //return;
            if (s == 0) {
               //  alert(printNum);
               /* if(printNum!=-1){
                    LODOP.SET_PRINTER_INDEX(printNum)
                }
                LODOP.PRINT() //直接打印
                */
              // LODOP.PRINT();
               
               if(printNum!=-1){
                    if(LODOP.SET_PRINTER_INDEX(printNum)){
                        LODOP.PRINT();
                        window.setTimeout(()=>{
                            if(this.isPrintClose=="Y"){
                                this.closes();
                            }
                        },1500)
                    }
               }else{
                 
                  // LODOP.SELECT_PRINTER();
                var count = LODOP.GET_PRINTER_COUNT();
                console.log("打印机个数====="+count);
                this.netWorkPrintMain=[];
                for (var i = 0; i < count; i++) {
                    //根据设备序号获取设备名
                    var msg = LODOP.GET_PRINTER_NAME(i);
                    console.log("第"+i+"个打印机："+msg);
                    let option={};
                    option.label=msg;
                    option.value=i;
                    
                    this.netWorkPrintMain.push(option);
                   
                }
                console.log(this.netWorkPrintMain,"this.netWorkPrintMain=====================")
                
                this.outerVisible=true;
                this.$nextTick(function () {
                    // Code that will run only after the
                    // entire view has been rendered
                    let that=this;
                   if( localStorage.getItem(localStorage.getItem("sCode")+that.printName+"print1")){
                        that.print1=Number(localStorage.getItem(localStorage.getItem("sCode")+that.printName+"print1"))
                        this.changePrint();
                    }else{
                        that.print1=""; 
                        this.netWorkPrintValue2="";
                        this.netWorkPrintValue="";
                    }
                   
                   
                  
                })
                
                
                         
                 
               }
                
                    
            }
            if (s == 1) {
                LODOP.PREVIEW() //打印预览
            }
            if (s == 2) {
                LODOP.PRINT_SETUP() //打印维护
            }
            if (s == 3) {
                LODOP.PRINT_DESIGN() //打印设计
            }
        },
        changePrint(){
            var strBridgesNameList=LODOP.Get_AOPrinters_List(this.print1,"name");
            var strBridgessIDList=LODOP.Get_AOPrinters_List(this.print1,"id");
            let NameOptions=new Array();
            let IDOptions=new Array();
            NameOptions=strBridgesNameList.split("\n");
            IDOptions=strBridgessIDList.split("\n");
            
            this.netWorkPrint=[];
            let isOk=false;
            for (var i in NameOptions){
                let option={};
                if(NameOptions[i]){
                    isOk=true;
                     option.label=NameOptions[i];
                    option.value=IDOptions[i]+";"+NameOptions[i];
                    this.netWorkPrint.push(option);
                }
               
            }
            if(isOk){
                this.showprint=true;
                this.showprint2=true;
                 this.netWorkPrintValue=IDOptions[0]+";"+NameOptions[0];
                 this.changePrint2();
            }else{
                this.netWorkPrintValue="";
            }
            
             
        },
        changePrint2(){
            var strBridgesNameList=LODOP.Get_AOBridge_SubPrinters_List(this.netWorkPrintValue,"name");
            var strBridgessIDList=LODOP.Get_AOBridge_SubPrinters_List(this.netWorkPrintValue,"id");



            let NameOptions=new Array();
            let IDOptions=new Array();
            NameOptions=strBridgesNameList.split("\n");
            IDOptions=strBridgessIDList.split("\n");
            
            this.netWorkPrint2=[];
            for (var i in NameOptions){
                let option={};
                if(NameOptions[i]){
                     option.label=NameOptions[i];
                    option.value=IDOptions[i];
                    this.netWorkPrint2.push(option);
                }
               
            }
            this.netWorkPrintValue2="";
            if(localStorage.getItem(localStorage.getItem("sCode")+this.printName+"netWorkPrintValue2")){
                this.netWorkPrintValue2=localStorage.getItem(localStorage.getItem("sCode")+this.printName+"netWorkPrintValue2")
            }
          
             
        },
        prints(){
            localStorage.setItem(localStorage.getItem("sCode")+this.printName+"netWorkPrintValue",this.netWorkPrintValue);
            localStorage.setItem(localStorage.getItem("sCode")+this.printName+"netWorkPrintValue2",this.netWorkPrintValue2);
            localStorage.setItem(localStorage.getItem("sCode")+this.printName+"print1",this.print1);
          
            if(this.netWorkPrintValue){
                LODOP.SET_BRIDGE_INDEX(this.netWorkPrintValue+","+this.netWorkPrintValue2)
               // LODOP.SET_PRINTER_INDEX(this.print1+","+this.netWorkPrintValue)
            }else{
                 LODOP.SET_PRINTER_INDEX(this.print1)
            }
            
            LODOP.PRINT();
            window.setTimeout(()=>{
                if(this.isPrintClose=="Y"){
                    this.closes();
                }
            },1500)
            this.outerVisible=false;
        },
        CreateOneFormPage3() {	
            LODOP=getLodop();  	
            LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_测试页一");
            LODOP.ADD_PRINT_RECT(77,74,409,345,0,2);
            LODOP.ADD_PRINT_ELLIPSE(351,140,140,60,0,1);
            LODOP.ADD_PRINT_RECT(299,133,344,42,1,1);
            LODOP.ADD_PRINT_TEXT(91,242,70,21,"测试页标题");
            LODOP.ADD_PRINT_TEXT(201,94,20,94,"测试页内容");
            LODOP.ADD_PRINT_TEXT(129,131,345,31,"测试内容一:9号宋体字是默认字体");
            LODOP.ADD_PRINT_TEXT(161,131,345,31,"测试内容二:11号普通宋体字正体");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
            LODOP.ADD_PRINT_TEXT(193,131,345,31,"测试内容三:13.5 号宋体字的粗体");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",13.5);
            LODOP.SET_PRINT_STYLEA(0,"Bold",1);
            LODOP.ADD_PRINT_TEXT(225,131,345,31,"测试内容四:15号宋体字的斜体");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",15);
            LODOP.SET_PRINT_STYLEA(0,"Italic",1);
            LODOP.ADD_PRINT_TEXT(260,131,345,31,"测试内容五:16号斜体字带下划线");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",16);
            LODOP.SET_PRINT_STYLEA(0,"Italic",1);
            LODOP.SET_PRINT_STYLEA(0,"Underline",1);
            LODOP.ADD_PRINT_TEXT(308,144,318,29,"测试内容六:黑体字居中");
            LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
            LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
            LODOP.ADD_PRINT_TEXT(350,300,170,66,"测试内容七:单行文字右靠齐超出区域宽度时则折行显示");
            LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
            LODOP.SET_PRINT_STYLEA(0,"Alignment",3);
            LODOP.ADD_PRINT_TEXT(428,79,400,23,"以上演示了位置、区域、字体、图形、线型等打印布局和风格。");
            LODOP.ADD_PRINT_LINE(119,76,118,481,0,1);
            LODOP.ADD_PRINT_LINE(78,127,420,128,0,1);
            LODOP.ADD_PRINT_LINE(79,76,118,127,0,1);			
	    },
         CreateOneFormPage(isControl) {
            LODOP = getLodop()
            //样式
            var olstyle1 = "";
            
            try{
                olstyle1= '<style>' + document.getElementById('olstyle1')[document.getElementById('olstyle1').length-1].innerHTML + '</style>'
            }catch(e){
                try{
                    olstyle1= '<style>' + document.getElementById('olstyle1').innerHTML + '</style>'
                }catch(e){}
            }
           // alert(olstyle1)
            //var olstyle1="";
            // var body = olstyle1 + '<body>' + document.getElementById('printContent').innerHTML + '</body>'
            //var body=this.$refs.print.innerHTML;
            var body=olstyle1+document.getElementsByClassName('printContent')[document.getElementsByClassName('printContent').length-1].innerHTML;
           
            //console.log(this.$refs.print);
            //var body = "";
            /*if(this.isEwm){
                 body = olstyle1 + '<body>' + document.getElementById('printContent').innerHTML + '</body>'
            }else*/
            //body=olstyle1 + '<body>' + this.content + '</body>'
            //console.log(body)
            LODOP.PRINT_INIT("超算软件_打印_HTML"); //打印初始化
           /* LODOP.ADD_PRINT_HTM(this.printData.c_ex7, this.printData.c_ex8, '100%','100%', body) //增加超文本项
            LODOP.SET_PRINT_MODE("PRINT_DUPLEX",2);//;0-不控制 1-不双面 2-双面(长边装订) 3-小册子双面(短边装订_长边水平)
            LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE",1);//1-纸盒 4-手动 7-自动 0-不控制*/
           
            LODOP.SET_PRINT_STYLEA(1,"Horient",2);
            LODOP.SET_PRINT_COPIES(this.printData.c_ex17);

            let c_ex22=0;
            if(this.printData.c_ex22){
                c_ex22=Number(this.printData.c_ex22)
            }

            if(this.urlPath){
                //alert(this.printDatas.printLeft)
                LODOP.SET_PRINT_PAGESIZE(this.printDatas.printType=="横" ? "2":"1", '210mm', '299mm', '') //设定纸张大小
                //LODOP.ADD_PRINT_HTM('0', '0', '100%','100%', body) //增加超文本项
                //LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', "100%")//设置缩放
                LODOP.ADD_PRINT_IMAGE(this.printDatas.printLeft ? this.printDatas.printLeft:0,this.printDatas.printTop ? this.printDatas.printTop:0,"100%","100%","<img  src='"+this.urlPath+"' style='max-width:100%'  />");
               // LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', "Auto-Width")//设置缩放
                let width=this.$refs.printImg.offsetWidth;
                let height=this.$refs.printImg.offsetHeight;
               
               // LODOP.ADD_PRINT_IMAGE(0,0,600,height,this.urlPath);  //不用<img>标签，直接地址获取源图
               // LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', "Auto-Width")//设置缩放
		       // LODOP.SET_PRINT_STYLEA(0,"Stretch",1);//(可变形)扩展缩放模式
                //LODOP.SET_PRINT_STYLEA(0,"Horient",2);
                //LODOP.SET_PRINT_STYLEA(0,"Stretch",1);
            }else{
               // alert(this.printData.c_ex9+"="+this.printData.c_ex10);

                if(c_ex22!=2&&c_ex22!=4&&c_ex22!=5&&isControl!="N")
                    LODOP.SET_PRINT_PAGESIZE(this.printData.c_ex5, this.printData.c_ex9+'mm', this.printData.c_ex10+'mm', '') //设定纸张大小
                    

                //LODOP.SET_PRINT_PAGESIZE(0, this.printData.c_ex9+'mm', this.printData.c_ex10+'mm', '') //设定纸张大小
                LODOP.ADD_PRINT_HTM(this.printData.c_ex7, this.printData.c_ex8, '100%','100%', body) //增加超文本项
                LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', this.printData.c_ex18)//设置缩放
            }
            c_ex22=c_ex22==4 ? 1:c_ex22;
            c_ex22=c_ex22==5 ? 0:c_ex22;
            console.log("打印是否双面："+c_ex22)
            LODOP.SET_PRINT_MODE("PRINT_DUPLEX",c_ex22);//;0-不控制 1-不双面 2-双面(长边装订) 3-小册子双面(短边装订_长边水平)
            LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE",1);//1-纸盒 4-手动 7-自动 0-不控制
           // LODOP.SET_PRINT_STYLE('FontSize', 18) //设置对象风格
            //LODOP.SET_PRINT_STYLE('Bold', 1) //设置对象风格
            //LODOP.ADD_PRINT_TEXT(50, 521, 130, 39, this.description) //增加纯文本项
            
            
            LODOP.SET_PREVIEW_WINDOW(2, 2, 0, 0, 0, '')//设置窗口

            // 打印二维码
            // LODOP.ADD_PRINT_BARCODE(23,23,233,233,"QRCode","https://blog.csdn.net/qq_43652509");
            //打印网址
            // LODOP.ADD_PRINT_URL(222,2000,2000,233,"https://blog.csdn.net/qq_43652509");
            //打印图片
            // LODOP.ADD_PRINT_IMAGE(100,100,400,400,"<img border='0' src='http://s1.sinaimg.cn/middle/4fe4ba17hb5afe2caa990&690' width='345' height='250'>");
            
           
        },
        CreateOneFormPage2() {
            LODOP = getLodop()
            //样式
            var olstyle1 = '<style>' + document.getElementById('olstyle1') + '</style>'
            //var olstyle1="";
            // var body = olstyle1 + '<body>' + document.getElementById('printContent').innerHTML + '</body>'
            //var body=this.$refs.print.innerHTML;
            var body=document.getElementsByClassName('printContent')[document.getElementsByClassName('printContent').length-1].innerHTML;
           // console.log(body)
            //console.log(this.$refs.print);
            //var body = "";
            /*if(this.isEwm){
                 body = olstyle1 + '<body>' + document.getElementById('printContent').innerHTML + '</body>'
            }else*/
            //body=olstyle1 + '<body>' + this.content + '</body>'
            //console.log(body)
            LODOP.PRINT_INIT("超算软件_打印_HTML"); //打印初始化
            let c_ex22=0;
            if(this.printData.c_ex22){
                c_ex22=Number(this.printData.c_ex22)
            }
            if(c_ex22!=2)
                LODOP.SET_PRINT_PAGESIZE(this.printData.c_ex5, this.printData.c_ex9+'mm', this.printData.c_ex10+'mm', '') //设定纸张大小
           
          
            LODOP.SET_PRINT_STYLEA(1,"Horient",2);
            LODOP.SET_PRINT_COPIES(this.printData.c_ex17);
            LODOP.ADD_PRINT_HTM(this.printData.c_ex7, this.printData.c_ex8, '100%','100%', body) //增加超文本项
            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', this.printData.c_ex18)//设置缩放
            
            LODOP.SET_PRINT_MODE("PRINT_DUPLEX",c_ex22);//;0-不控制 1-不双面 2-双面(长边装订) 3-小册子双面(短边装订_长边水平)
            LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE",1);//1-纸盒 4-手动 7-自动 0-不控制
           // LODOP.SET_PRINT_STYLE('FontSize', 18) //设置对象风格
            //LODOP.SET_PRINT_STYLE('Bold', 1) //设置对象风格
            //LODOP.ADD_PRINT_TEXT(50, 521, 130, 39, this.description) //增加纯文本项
            
            
            LODOP.SET_PREVIEW_WINDOW(2, 2, 0, 0, 0, '')//设置窗口
            // 打印二维码
            // LODOP.ADD_PRINT_BARCODE(23,23,233,233,"QRCode","https://blog.csdn.net/qq_43652509");
            //打印网址
            // LODOP.ADD_PRINT_URL(222,2000,2000,233,"https://blog.csdn.net/qq_43652509");
            //打印图片
            // LODOP.ADD_PRINT_IMAGE(100,100,400,400,"<img border='0' src='http://s1.sinaimg.cn/middle/4fe4ba17hb5afe2caa990&690' width='345' height='250'>");
      
           
        },
        cm2px(cm) {
            var dpi = this.getDPI();
            var pixel = parseFloat(cm) / 25.4 * dpi[0];	//只计算x轴的dPI	
            return (parseInt(pixel))
        },
        getDPI() { 
            var arrDPI = new Array(); 
            if (window.screen.deviceXDPI != undefined) {//ie 9 
                arrDPI[0] = window.screen.deviceXDPI; 
                arrDPI[1] = window.screen.deviceYDPI;
            }else {//chrome firefox
                var tmpNode = document.createElement("DIV"); 
                tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden"; 
                document.body.appendChild(tmpNode); 
                arrDPI[0] = parseInt(tmpNode.offsetWidth); 
                arrDPI[1] = parseInt(tmpNode.offsetHeight); 
                tmpNode.parentNode.removeChild(tmpNode); 
            
            } 
            
            return arrDPI;
        },
        qrcode(id,flagWidth,flagValue) {
            let qrcode = new QRCode(id, {
                width: flagWidth,  
                height: flagWidth,
                text: flagValue, // 二维码地址
            })
        },
        
        initDevice(){
            let sef=this;
            let initUrl = this.apiUrl + 'InitialDevice?id=2&width=580&height=380';
           
            //步骤一:创建异步对象
            var ajax = new XMLHttpRequest();
            //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
            ajax.open('get',initUrl);
            //步骤三:发送请求
            ajax.send();
            //步骤四:注册事件 onreadystatechange 状态改变就会调用
            ajax.onreadystatechange = function () {   
                if (ajax.readyState==4 &&ajax.status==200) {
                    if(ajax.responseText){
                        sef.isPolling=true;
                         sef.canvas.src="";
                        ///sef.context.clearRect(0, 0, sef.canvas.width, sef.canvas.height);
                        sef.getInk();
                        sef.getStatus();
                    }
                    //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的　　　　console.log(ajax.responseText);//输入相应的内容  　　}
                }
            }
          
            
        },
        getInk(){
            let getInkUrl = this.apiUrl + 'GetInks';
            
            let sef=this;
            var timeId = setTimeout(function () {
                clearTimeout(timeId);
                if(sef.isPolling){
                    //步骤一:创建异步对象
                    var ajax = new XMLHttpRequest();
                    //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
                    ajax.open('get',getInkUrl);
                    //步骤三:发送请求
                    ajax.send();
                    //步骤四:注册事件 onreadystatechange 状态改变就会调用
                    ajax.onreadystatechange = function () {   
                        if (ajax.readyState==4 &&ajax.status==200) {
                            
                            let text=ajax.responseText
                            let dataInfos =JSON.parse(text);
                            try{
                                dataInfos =JSON.parse(dataInfos);
                            }catch(e){}
                            for(let i=0;i<dataInfos.length;i++){

                                let item=dataInfos[i];
                                if (item.EventType === 0) {
                                    //sef.drawImage(value.Image);
                                    sef.LastSignatureBase64Data = item.Image;
                                    sef.drawImage(sef.LastSignatureBase64Data);
                                }
                            }
                            if(sef.isSignStop=='N')
                                sef.getInk();
                            //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的　　　　console.log(ajax.responseText);//输入相应的内容  　　}
                        }
                    }
                }
                
            },500);
        },
        getStatus(){
            let confirmStatusUrl = this.apiUrl + 'GetDeviceConfirmOrCancelKeyStatus';
            let sef=this;
            var timeId = setTimeout(function () {
                clearTimeout(timeId);
                if(sef.isPolling){
                    //步骤一:创建异步对象
                    var ajax = new XMLHttpRequest();
                    //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
                    ajax.open('get',confirmStatusUrl);
                    //步骤三:发送请求
                    ajax.send();
                    //步骤四:注册事件 onreadystatechange 状态改变就会调用
                    ajax.onreadystatechange = function () {   
                        if (ajax.readyState==4 &&ajax.status==200) {
                            
                            let text=ajax.responseText.replace("\"","").replace("\"","");
                            if (text == "1") {
                                //sef.drawImage(sef.LastSignatureBase64Data);
                               // console.log("11111")
                                //sef.isPolling=false;
                            } else if (text == "0") {
                                sef.clearInk();
                              //  console.log("clear===")
                            }
                            if(this.isSignStop=='N')
                                sef.getStatus();
                            //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的　　　　console.log(ajax.responseText);//输入相应的内容  　　}
                        }
                    }
                }
                
            },500);
        },
        clearInk(){
            let sef=this;
            var clrInkUrl = this.apiUrl + 'Clear';
            var ajax = new XMLHttpRequest();
            //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
            ajax.open('get',clrInkUrl);
            //步骤三:发送请求
            ajax.send();
            //步骤四:注册事件 onreadystatechange 状态改变就会调用
            ajax.onreadystatechange = function () {   
                if (ajax.readyState==4 &&ajax.status==200) {
                    
                    sef.canvas.src="";
                    sef.signatureImg="";
                    //sef.context.clearRect(0, 0, sef.canvas.width, sef.canvas.height);
                    //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的　　
                    
                }
            }
        },
        drawImage(base64) {
            this.isSaveSignature=true;
            //console.log("111")
            var dataUrl = 'data:image/jpeg;base64,';
            let sef=this;
            dataUrl = dataUrl + base64;
            sef.canvas.src=dataUrl;
            sef.signatureImg=dataUrl;

            try{
                let elms=document.getElementsByClassName('ppCanvasBak');
                for(let i=0;i<elms.length;i++){
                    elms[i].src=dataUrl;
                }
            }catch(e){}
            

            /*console.log(sef.context)
            // 在image中載入圖檔，再畫到canvas呈現
            var img = new Image();

            img.addEventListener('load', function () {
                sef.context.drawImage(this, 0, 0, sef.canvas.width, sef.canvas.height);
            }, false);

            img.src = dataUrl;*/
        },
        uninitDevice() {
            this.trans=false;
            //event.preventDefault();
            this.isPolling = false;
            let sef=this;
            var uninitUrl = this.apiUrl + 'UninitialDevice?id=2';
            var ajax = new XMLHttpRequest();
            //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
            ajax.open('get',uninitUrl);
            //步骤三:发送请求
            ajax.send();
            //步骤四:注册事件 onreadystatechange 状态改变就会调用
            ajax.onreadystatechange = function () {   
                if (ajax.readyState==4 &&ajax.status==200) {
                    if(ajax.responseText){
                        sef.canvas.src="";
                        
                        //sef.signatureImg="";
                       // sef.context.clearRect(0, 0, sef.canvas.width, sef.canvas.height);
                    }
                   
                }
            }

        },
        uninitDevice2() {
            this.trans=false;
            //event.preventDefault();
            this.isPolling = false;
            let sef=this;
            var uninitUrl = this.apiUrl + 'UninitialDevice?id=2';
            var ajax = new XMLHttpRequest();
            //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
            ajax.open('get',uninitUrl);
            //步骤三:发送请求
            ajax.send();
            //步骤四:注册事件 onreadystatechange 状态改变就会调用
            ajax.onreadystatechange = function () {   
                if (ajax.readyState==4 &&ajax.status==200) {
                    if(ajax.responseText){
                       sef.isSignStop="Y"
                    }
                   
                }
            }

        },

        initDeviceEsp560(){
            this.isSignStop="N"
            this.$jsonp("http://127.0.0.1:29999/HWPenSign/HWGetDeviceStatus",{}).then(data=>{
                console.log(data,"initDeviceEsp560========================")
                this.openDeviceEsp560();
            });
           
            
        },
        openDeviceEsp560(){
            this.$jsonp("http://127.0.0.1:29999/HWPenSign/HWInitialize",{
                "nLogo":"签字",
                "nPenwidth":"2",
                "nOrgX":"100",
                "nOrgY":"200",
                "width":"500",
                "height":"300",
                "fingerFap":"1",
                "key":"98511ED31057FB9E5E6B9BA67967582D"
            }).then(data=>{
                console.log(data,"openDeviceEsp560========================")
                if(data.msgID == 0){
                    let that=this;
                    window.setTimeout(function(){
                        that.getSignEsp560();
                    },1000)
                }
            });
            
          
            
        },
        getSignEsp560(){
            this.$jsonp("http://127.0.0.1:29999/HWPenSign/HWGetSign",{
                "nImageType":"3",
                "nImageWidth":"500",
                "nImageHeight":"300"
            }).then(data=>{
                console.log(data,"getSignEsp560========================")
                if(data.msgID == 0){
                    this.isSaveSignature=true;
           
                    
                    let sef=this;
                    let dataUrl=data.message;
                    sef.canvas.src=dataUrl;
                    sef.signatureImg=dataUrl;
                   // document.getElementById("signimg").src = data.message;
                    if(this.isSignStop=='N'){
                        let that=this;
                        window.setTimeout(function(){
                            that.getSignEsp560();
                        },1000)
                    }
                }else if(data.msgID == -15){
                  
                    
                }
            });
        
        },
        uninitDeviceESP560() {
            this.$jsonp("http://127.0.0.1:29999/HWPenSign/HWFinalizen",{
               
            }).then(data=>{
                console.log(data,"uninitDeviceESP560========================")
                this.isSignStop="Y"
                this.canvas.src="";
            });

        },
        resetDeviceESP560() {
            this.$jsonp("http://127.0.0.1:29999/HWPenSign/HWClearPenSign",{
               
            }).then(data=>{
                console.log(data,"resetDeviceESP560========================")
                //this.isSignStop="Y"
                this.canvas.src="";
            });

        },
        resetSigns(){
            if(this.signtypes=="ESP560"){
                this.isSignReset="Y"
                this.initDeviceEsp560();
            }else
                this.initDevice();
            this.showQm3=true;
        },
        resetSign(){
            if(this.signTypes=="ESP560"){
                this.resetDeviceESP560();
            }
        },
        transs(){
            if(this.trans){
                this.trans=false;
            }else{
                this.trans=true;
            }
        },
        rotateBase64Img(src, edg, callback) {

            var canvas = document.createElement("canvas");
            var ctx = canvas.getContext("2d");

            var imgW;//图片宽度
            var imgH;//图片高度
            var size;//canvas初始大小

            if (edg % 90 != 0) {
                console.error("旋转角度必须是90的倍数!");
                throw '旋转角度必须是90的倍数!';
            }
            (edg < 0) && (edg = (edg % 360) + 360)
            const quadrant = (edg / 90) % 4; //旋转象限
            const cutCoor = {sx: 0, sy: 0, ex: 0, ey: 0}; //裁剪坐标

            var image = new Image();
            image.crossOrigin = "anonymous"
            image.src = src;

            image.onload = function () {

                imgW = image.width;
                imgH = image.height;
                size = imgW > imgH ? imgW : imgH;

                canvas.width = size * 2;
                canvas.height = size * 2;
                switch (quadrant) {
                    case 0:
                        cutCoor.sx = size;
                        cutCoor.sy = size;
                        cutCoor.ex = size + imgW;
                        cutCoor.ey = size + imgH;
                        break;
                    case 1:
                        cutCoor.sx = size - imgH;
                        cutCoor.sy = size;
                        cutCoor.ex = size;
                        cutCoor.ey = size + imgW;
                        break;
                    case 2:
                        cutCoor.sx = size - imgW;
                        cutCoor.sy = size - imgH;
                        cutCoor.ex = size;
                        cutCoor.ey = size;
                        break;
                    case 3:
                        cutCoor.sx = size;
                        cutCoor.sy = size - imgW;
                        cutCoor.ex = size + imgH;
                        cutCoor.ey = size + imgW;
                        break;
                }


                ctx.translate(size, size);
                ctx.rotate(edg * Math.PI / 180);
                ctx.drawImage(image, 0, 0);

                var imgData = ctx.getImageData(cutCoor.sx, cutCoor.sy, cutCoor.ex, cutCoor.ey);
                if (quadrant % 2 == 0) {
                    canvas.width = imgW;
                    canvas.height = imgH;
                } else {
                    canvas.width = imgH;
                    canvas.height = imgW;
                }
                ctx.putImageData(imgData, 0, 0);
                callback(canvas.toDataURL())
            };
            }

    }
}
</script>
<style scoped>
    .skins{
        width:100%;
        height:100%;
        text-align:center;
        position:absolute;
        left:0;
        top:0;
        z-index:100000;
        background:#fff;
        display:flex;
        align-items: center;
        justify-content: center;
    }
    .commonPrint{
        height:100%;
        width:100%;
        display:flex;
        flex-direction: column;
        position: relative;
        text-align: left;
    }

    #printContent{
        flex:1;
    }
    .btn{
        padding:10px;
        border-bottom:1px solid #ddd;
        background: gainsboro;
    }
    .head{
        padding:10px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        border-bottom: 1px solid #ddd;
        background:#fff;
        display:flex;
        flex-direction: row;
    }
    .head_left{
        flex:1;
    }
    .head_right{
        width:120px;
        text-align: center;
    }
    .el-form-item{
        margin-bottom:5px;
    }
    #printContent{
        overflow:auto;
    }
    .tds{
        border:1px solid #000;
    }
    .c{
        text-align:center;
    }
    .el-tabs__content2{
        padding-top:0;
    }
    .signatures >>> .el-dialog{
        width:720px;
    }
    .signatures >>> .el-dialog{
        width:80%;
    }
    .pringsleect>>> .el-dialog{
        width:500px;
    }
    .commonPrint_trans{
        
        transform: rotate(180deg);
        -o-transform: rotate(180deg);
        -webkit-transform: rotate(180deg);
        -moz-transform: rotate(180deg);
    }
</style>
<style>
@page {
    size: auto;
    margin: 0mm;
  }
  .procedure{
      word-wrap:break-word;
   }
@media print {
    /*最外层打印节点*/
    .printContent {
        display:block;
        height: auto;
        overflow: hidden;
    }
    .towPage{
        margin-left:50px;
    }
}
@media screen{
    #printContentDetail{
        margin-left:auto;
        margin-right:auto;
    }
}
.td_empty{
    height:0 !important;
}
</style>